/**
   Counts the number of times a character appears in a string.
*/

public class CharCounter
{
   /**
      Returns the number of times that a target character
      appears in a string.
      @param source the input string
      @param ch the character to be counted (a string of length 1)
      @return the number of times the target character
      appears in the source
   */
   public static int countChar(String str, String find)
   {
      int count = 0;
		int index = 0;
		while ((index = str.indexOf(find, index)) != -1) {
			index = index + find.length();
			count++;
		}
		return count;
   }
   
   public static void main(String[] args)
   {
      System.out.println("Character appears " + countChar("abracadabra","a") + " times.");
   }
}